package com.pearl.jacksoncore.demo.databind.module;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.util.VersionUtil;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Set;

/**
 * @author TD
 * @version 1.0
 * @date 2024/4/10
 */
public class ModuleTest {
    public static void main(String[] args) {
        ObjectMapper objectMapper = new ObjectMapper();
        // 创建版本
        Version version = VersionUtil.parseVersion("1.0.0", "com.pearl", "jackson-datatype-my");
        // 创建模块
        SimpleModule myModule = new SimpleModule("myModule", version);
        // 添加序列化器/反序列化器
        myModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        myModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        //objectMapper.registerModule(myModule);

        objectMapper.findAndRegisterModules();// SPI发现并注册
        Set<Object> moduleIds = objectMapper.getRegisteredModuleIds();
        System.out.println(moduleIds);

        // 查询模块
        List<Module> moduleList = ObjectMapper.findModules();


    }
}
